{% extends "base.html" %}{% load base_tags %}
{% block content %}
{% if user.is_authenticated %}
	{% hintblock %}
	Du bist angemeldet als <strong>{{ user.username }}</strong>!
	{% endhintblock %}
{% endif %}
<div id="feed-table">
	<img id="ajax-loader" src="{{ MEDIA_URL }}images/ajax-loader-submenu.gif" alt="Loading ..." style="padding-top: 8px;" />
	<strong>Lade ...</strong>
</div>
<script type="text/javascript">
	var is_dashboard={% if is_dashboard %}true{% else %}false{% endif %};
	var errorlog_page = "";

	$(document).ready(function() {
		if (is_dashboard)
			reload_dashboard();
		else
			reload_errorlog(errorlog_page);
	});
	function reload_dashboard() {
		$.ajax({
			url: "{% url feedmanager_get_feed_table %}",
			cache: false,
			success: function(response) {
				if (response !== null && response !== "")
					$('#feed-table').html(response.data);
			},
			error: function() {
				showDialogMessage('Die Feed-Tabelle konnte nicht abgerufen werden!');
			},
		});
	}
	function reload_errorlog(page) {
		var url = "{% url feedmanager_get_error_table %}";
		if (page != "") {
			url += '?page=' + page;
			errorlog_page = page;
		}
		$.ajax({
			url: url,
			cache: false,
			success: function(response) {
				if (response !== null && response !== "")
					$('#feed-table').html(response.data);
			},
			error: function() {
				showDialogMessage('Das Errorlog konnte nicht abgerufen werden!');
			},
		});
	}
	function remove_feed(id) {
		message = 'Willst Du den Feed "' + $('#feed' + id + '_name').html() + '" abbestellen?'; 
		$('<div></div>')
			.html(message)
			.dialog({
				closeText: 'Schließen',
				modal: true,
				resizable: false,
				draggable: false,
				buttons: {
					"Nein": function() {
						$(this).dialog("close"); 
					}, 
					"Ja": function() { 
						$(this).dialog("close"); 	
						$.ajax({
							url: "{% url feedmanager_remove_feed %}",
							data: ({'id': id}),
							cache: false,
							success: function(response) {
								if (response !== null && response !== "") {
									if (is_dashboard)
										$('#feed' + id).fadeOut("slow");
									else
										reload_errorlog(errorlog_page);
								}
							},
							error: function() {
								showDialogMessage('Beim Abbestellen des Feeds ist ein Fehler aufgetreten!');
							},
						});
				},
			},
			title: 'Bestätigung',
			width: 400,
		});
	}
</script>
{% endblock %}